Ext.setup({
	icon : 'img/icon.png',
	tabletStartupScreen : 'img/tablet_startup.png',
	phoneStartupScreen : 'img/phone_startup.png',
	glossOnIcon: false,
    onReady: function() {
	
    	Ext.regModel('Cars', {
		    fields: [
		        {name: 'text', type: 'string'}
		    ]
		});

		Ext.regModel('CarInfor', {
		     fields: ['carNO','carCode','abbreviation','thecolor','salesStatus','stockStatus','carType','remarks', 'storagesites']
		});
		
		//资源列表-----------开始----------------------
		var list_resource = new Ext.List({
			align: 'center',
	        store: new Ext.data.Store({
				model: 'CarInfor',
				pageSize: 10,
				autoLoad: true,
				proxy: new Ext.data.AjaxProxy({
					startParam: 'start',
	    			limitParam: 'limit',
					url : '../car/CarInformationController/search.action?stockStatus=' + encodeURI(encodeURI('资源')),
			        extraParams: {},
			        reader: {
			            type: 'json',
			            root: 'invdata'
			        }
				})
			}),
	        itemTpl: new Ext.XTemplate(
	        	'<div>{carNO}</div>',
	        	'<div>{carCode} ~ {abbreviation} ~ {thecolor} ~ {salesStatus} ~ {stockStatus} ~ {carType} ~ {remarks} </div>'
	        ),
	        selModel: {
                mode: 'SINGLE',
                allowDeselect: true
            }
		});
		//资源列表-----------结束----------------------
		
		//在途列表--------------开始-----------
		var list_onway = new Ext.List({
			align: 'center',
	        store: new Ext.data.Store({
				model: 'CarInfor',
				pageSize: 10,
				autoLoad: true,
				proxy: new Ext.data.AjaxProxy({
					startParam: 'start',
	    			limitParam: 'limit',
					url : '../car/CarInformationController/search.action?stockStatus=' + encodeURI(encodeURI('在途')),
			        extraParams: {},
			        reader: {
			            type: 'json',
			            root: 'invdata'
			        }
				})
			}),
	        itemTpl: new Ext.XTemplate(
	        	'<div>{carNO}</div>',
	        	'<div>{carCode} ~ {abbreviation} ~ {thecolor} ~ {salesStatus} ~ {stockStatus} ~ {carType} ~ {remarks} </div>'
	        ),
	        selModel: {
                mode: 'SINGLE',
                allowDeselect: true
            }
		});
		//在途列表--------------结束----------
		
		//---在库列表---------开始------------
		var list_instock = new Ext.List({
			align: 'center',
	        store: new Ext.data.Store({
				model: 'CarInfor',
				pageSize: 10,
				autoLoad: true,
				proxy: new Ext.data.AjaxProxy({
					startParam: 'start',
	    			limitParam: 'limit',
					url : '../car/CarInformationController/search.action?stockStatus=' + encodeURI(encodeURI('在库')),
			        extraParams: {},
			        reader: {
			            type: 'json',
			            root: 'invdata'
			        }
				})
			}),
	        itemTpl: new Ext.XTemplate(
	        	'<div>{carNO}</div>',
	        	'<div>{carCode} ~ {abbreviation} ~ {thecolor} ~ {salesStatus} ~ {stockStatus} ~ {carType} ~ {remarks} ~ {storagesites}</div>'
	        ),
	        selModel: {
                mode: 'SINGLE',
                allowDeselect: true
            }
		});
		//---在库列表---------结束-------------
		
		//---现货列表---------开始------------
		var list_sale = new Ext.List({
			align: 'center',
	        store: new Ext.data.Store({
				model: 'CarInfor',
				pageSize: 10,
				autoLoad: true,
				proxy: new Ext.data.AjaxProxy({
					startParam: 'start',
	    			limitParam: 'limit',
					url : '../car/CarInformationController/search.action?stockStatus=' + encodeURI(encodeURI('在库')) + '&salesStatus=' + encodeURI(encodeURI('可售')),
			        extraParams: {},
			        reader: {
			            type: 'json',
			            root: 'invdata'
			        }
				})
			}),
	        itemTpl: new Ext.XTemplate(
	        	'<div>{carNO}</div>',
	        	'<div>{carCode} ~ {abbreviation} ~ {thecolor} ~ {salesStatus} ~ {stockStatus} ~ {carType} ~ {remarks} ~ {storagesites}</div>'
	        ),
	        selModel: {
                mode: 'SINGLE',
                allowDeselect: true
            }
		});
		
		//---现货列表---------结束-------------
		var grid = new Ext.ux.TouchGridPanel({
			align: 'center',
			store : new Ext.data.Store({
				model : "CarInfor",
				pageSize: 10,
				autoLoad: true,
				proxy : {
					type: "ajax",
					url : '../car/CarInformationController/search.action?stockStatus=' + encodeURI(encodeURI('在途')),
					reader: {
						type: "json",
						totalProperty: "total",
						root: "invdata"
					}
				}
			}),
			plugins: [new Ext.ux.touch.PagingToolbar()],
			colModel    : [{
					header   : "车型",
					mapping  : "abbreviation",
					flex     : 2
				},{
					header   : "颜色",
					mapping  : "thecolor",
					style    : "text-align: center;"
				},{
					header   : "销售",
					mapping  : "salesStatus",
					style    : "text-align: center;"
				}
			],
			listeners: {
				doubletap: function() {alert(12);}
			}
		});
		
		
		//-----测试-------
		var testNodeList = new Ext.NestedList({
		 	store: new Ext.data.TreeStore({
			    model: 'Cars',
			    pageSize: 10,
			    autoLoad: true,
			    proxy: {
			        type: 'ajax',
			        url: '../car/CarInformationController/searchOnWayCars.action?stockStatus=' + encodeURI(encodeURI('在途')),
			        reader: {
			            type: 'tree',
			            root: 'items'
			        }
			    }
			})
		 })
		
		new Ext.TabPanel({
			fullscreen: true,
            type: 'dark',
            sortable: true,
            items: [{
                title: '资源',
                layout: 'fit',
                items:[list_resource],
                plugins: [new Ext.ux.touch.PagingToolbar({store:list_resource.store})]
//                dockedItems: [
//                	{
//		                xtype: 'toolbar',
//		                ui: 'light',
//		                dock: 'bottom',
//		                items: [{
//				            text: '刷新',
//				            ui: 'round',
//				            handler: function() {
//				            	list_resource.store.removeAll();
//				            	list_resource_start = 0;
//				            	list_resource_store.load({params:{start: list_resource_start, limit: 25}});
//				            }
//		                }]
//		            }
//                ],
            }, {
                title: '在途',
                layout: 'fit',
                items:[list_onway],    
                plugins: [new Ext.ux.touch.PagingToolbar({store:list_onway.store})]
            }, 
            {
                title: '在库',
                layout: 'fit',
                items:[list_instock],
				plugins: [new Ext.ux.touch.PagingToolbar({store:list_instock.store})]
            },
            {
                title: '现货',
                layout: 'fit',
                items:[list_sale],
                plugins: [new Ext.ux.touch.PagingToolbar({store:list_sale.store})]
            }
            ,
            {
            	title: '在途',
            	layout:'fit',
            	items:[grid]
            },
            {
            	title: 'NodeList',
            	layout:'fit',
            	items:[testNodeList]
            }]
		});
	}
});